
load('summary_data/figs7_8_A12_A13_A14.rda')
source('utils.R')

c4 = render_basic(c4) +
  scale_y_continuous(labels = scales::label_percent(big.mark = ','),
                     breaks = c(seq(-1, 2, .5), seq(3, 10, 1))) +
  scale_shape_manual(name = 'Ethnicity',
                     values = c(20, 4),
                     labels = c('B', 'W')) +
  labs(
    x = element_blank(),
    y = '% Change from 2012 Copartisan',
    color = element_blank(),
    subtitle = 'Ethnicity (Black, White)'
  )

c6 = render_basic(c6) +
  scale_y_continuous(labels = scales::label_percent(big.mark = ','),
                     breaks = c(seq(-1, 2, .5), seq(3, 10, 1))) +
  scale_shape_manual(name = 'Ethnicity',
                     values = c(20, 4),
                     labels = c('A', 'W')) +
  labs(
    x = element_blank(),
    y = '% Change from 2012 Copartisan',
    color = element_blank(),
    subtitle = 'Ethnicity (Asian, White)'
  )

c8 = render_basic(c8) +
  scale_y_continuous(labels = scales::label_percent(big.mark = ','),
                     breaks = c(seq(-1, 2, .5), seq(3, 10, 1))) +
  scale_shape_manual(name = 'Ethnicity',
                     values = c(20, 4),
                     labels = c('H', 'W')) +
  labs(
    x = element_blank(),
    y = '% Change from 2012 Copartisan',
    color = element_blank(),
    subtitle = 'Ethnicity (Hispanic, White)'
  )

legend = c4 + guides(shape = 'none') + theme(legend.position = 'bottom')
legend = get_legend_35(legend)

c4 = c4 +
  scale_y_continuous(labels = scales::label_percent(),
                     breaks = c(seq(-1, 2, .5), seq(3, 6, 1))) +
  coord_cartesian(ylim = c(-1, 6)) +
  guides(color = 'none', shape = guide_legend(nrow = 1)) +
  scale_shape_manual(
    name = element_blank(),
    values = c(20, 4),
    labels = c('Black', 'White')
  ) +
  labs(subtitle = element_blank(), shape = element_blank()) +
  theme(plot.margin = margin(t = -0.5, 1, 1, 1))

c6 = c6 +
  scale_y_continuous(labels = scales::label_percent(),
                     breaks = c(seq(-1, 2, .5), seq(3, 6, 1))) +
  coord_cartesian(ylim = c(-1, 6)) +
  guides(color = 'none', shape = guide_legend(nrow = 1)) +
  scale_shape_manual(
    name = element_blank(),
    values = c(20, 4),
    labels = c('Asian', 'White')
  ) +
  labs(subtitle = element_blank(),
       y = element_blank(),
       shape = element_blank()) +
  theme(plot.margin = margin(t = -0.5, 1, 1, 1))

c8 = c8 +
  scale_y_continuous(labels = scales::label_percent(),
                     breaks = c(seq(-1, 2, .5), seq(3, 6, 1))) +
  coord_cartesian(ylim = c(-1, 6)) +
  guides(color = 'none', shape = guide_legend(nrow = 1)) +
  scale_shape_manual(
    name = element_blank(),
    values = c(20, 4),
    labels = c('Hispanic', 'White')
  ) +
  labs(subtitle = element_blank(),
       y = element_blank(),
       shape = element_blank()) +
  theme(plot.margin = margin(t = -0.5, 1, 1, 1))

plot = plot_grid(c4 + guides(shape = 'none'),
                 c6 + guides(shape = 'none'),
                 c8 + guides(shape = 'none'),
                 nrow = 1)

plot = plot_grid(plot, legend, rel_heights = c(9, .35), nrow = 2)

shapes = plot_grid(get_legend_35(c4),
                   get_legend_35(c6),
                   get_legend_35(c8),
                   nrow = 1)

plot = plot_grid(shapes, plot, rel_heights = c(.5, 9), nrow = 2)

ggsave(filename = 'figures/figA13.pdf', plot = plot, width = 8, height = 5, units = 'in')
